package com.nyist.controller;

import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.nyist.entity.Manage;
import com.nyist.entity.Role;
import com.nyist.entity.Show;
import com.nyist.service.ManageService;
import com.nyist.service.RelationService;
/**
 * 管理员登录后进入的页面可以是一个权限管理页面
 * @author 18077
 *
 */
@Controller
@RequestMapping(value = "super")
public class SuperManageController {
	@Autowired
	@Qualifier("manageService")
	private ManageService manageService;
	
	@Autowired
	@Qualifier("relationService")
	private RelationService relationService;
	@RequestMapping(value="manageList")
	public String superList(HttpServletRequest request){
		HttpSession session = request.getSession();
		session.setAttribute("role", "超级管理员");
		List<Manage> manages = manageService.queryAllManage();
		
		List<Show> shows = new ArrayList<Show>();
		String mid = "";  //用户id
		int roleid;     //角色id
		String des = "";//角色描述
		String rN = "";  //角色名字
		for (Manage m : manages) {
			mid = m.getId();
			roleid = relationService.queryRoleByManageid(mid);
			des = relationService.queryDiscriptionByManageid(roleid);
			rN = relationService.queryRoleByRoleid(roleid);
			//第一个用户的角色信息
			Show show = new Show();
			show.setManageid(mid);
			show.setRole(rN);
			show.setDescription(des);
			show.setUsername(m.getUsername());
			shows.add(show);
		}
		session.setAttribute("shows", shows);
		return "redirect:/managelist.jsp";
	}
}
